package com.boomsecret.annotation;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Created by wangjinliang on 2018/1/16.
 */
public class UseCaseAnnotationHandler {

    private static Map<Integer, Integer> methodInvokeCount = new HashMap<>();

    public static void countMethodInvokeNumber(Method method) {
        UseCaseAnnotation annotation = method.getAnnotation(UseCaseAnnotation.class);
        if (Objects.nonNull(annotation)) {
            int id = annotation.id();
            Integer orDefault = methodInvokeCount.getOrDefault(id, 0);
            methodInvokeCount.put(id, orDefault + 1);
        }
    }

    public static Map<Integer, Integer> getMethodInvokeCount() {
        return methodInvokeCount;
    }
}
